﻿@using ZX.Tools
@using ZX.Model
@model MyEntertain
@{
    Sys_UserModel user = ViewBag.User;
    List<Approval_Log> listLog = ViewBag.ListLog ?? new List<Approval_Log>();
    List<Dictionary> listEntertainUnit = ViewBag.ListEntertainUnit ?? new List<Dictionary>();
    //List<Approval_User> listAuser = ViewBag.ListAUser ?? new List<Approval_User>();
    List<Approval> listApproval = ViewBag.ListApproval ?? new List<Approval>();
}
<link href="~/Static/styles/bootstrap.min.css" rel="stylesheet" />
<link href="~/Static/js/layer/need/layer.css" rel="stylesheet" />
<link href="~/Static/js/Validform/css/style.css" rel="stylesheet" />
<link href="~/Static/js/layui/css/layui.css" rel="stylesheet" />
<script src="/Static/js/jquery/jquery-1.11.1.min.js"></script>
<script src="~/Static/js/layui/layui.js"></script>
<script src="~/Static/js/jquery/form/min.js"></script>
<script src="~/Static/js/Validform/js/Validform_v5.3.2_min.js"></script>
<script src="~/Static/js/admin.min.js"></script>
<script src="~/Static/js/layer/layer.js"></script>
<script src="~/Static/js/layer/layer.tools.js"></script>
<style>
    .panel {
        border: 2px solid #e5e5e5 !important;
    }

    .perip-box {
        padding: 20px;
        margin-top: 10%;
    }

    .top-navbar-index {
        position: inherit;
        width: 100%;
        margin-bottom: 0;
    }

    .with-menu {
        padding: 20px;
    }
    .table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
        font-size: 14px;
    }
</style>
@Html.Raw(ViewBag.SysAdminMainNavbar)
<div class='with-menu'>
    <div class='panel'>
        <div class='panel-heading'><strong><i class='icon-building'></i>招待申请单</strong></div>
        <div class='panel-body'>
            <form action="/MyEntertain/SaveData" method="post" class="form" id="formMyEntertain">
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="Status" value="@Model.Status" />
                <table class='table table-bordered' style="border: 1px solid #ddd;">
                    <tr>
                        <th class='text-center w-100px'>申请部门</th>
                        <td>
                            @user.DeptName
                        </td>
                        <th class="text-center w-100px">申请人</th>
                        <td>
                            @user.RealName
                        </td>
                        <th class='text-center w-100px'>日期</th>
                        <td>
                            @(Model.AddTime.ToDateFormat("yyyy-MM-dd"))
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">客人单位</th>
                        <td colspan="2"><input name="KeCompanyName" class="form-control" value="@Model.KeCompanyName" datatype="*" nullmsg="请填写客人单位" /></td>
                        <th class="text-center">客人人数</th>
                        <td colspan="2">
                            <input name="KeCount" class="form-control" value="@Model.KeCount" onkeypress="$.admin.keyPress(this)"
                                   onkeyup="$.admin.keyUp(this)"
                                   onblur="$.admin.keyBlur(this)" />
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">陪餐人员</th>
                        <td colspan="5"><input name="AccompanyDinner" class="form-control" value="@Model.AccompanyDinner" placeholder="陪餐人员姓名" /></td>
                    </tr>
                    <tr>
                        <th class="text-center">招待事项</th>
                        <td colspan="2">
                            <input type="checkbox" class="form-checkbox" name="ESxiang" value="内部就餐" @((Model.ESxiang + "").Contains("内部就餐") ? "checked" : "") datatype="*" nullmsg="请选择招待事项" />内部就餐&nbsp;
                            <input type="checkbox" class="form-checkbox" name="ESxiang" value="外部就餐" @((Model.ESxiang + "").Contains("外部就餐") ? "checked" : "") datatype="*" nullmsg="请选择招待事项" />外部就餐&nbsp;
                            <input type="checkbox" class="form-checkbox" name="ESxiang" value="住宿" @((Model.ESxiang + "").Contains("住宿") ? "checked" : "") datatype="*" nullmsg="请选择招待事项" />住宿&nbsp;
                        </td>
                        <th class="text-center">招待级别</th>
                        <td colspan="2">
                            <input type="checkbox" class="form-checkbox" name="ELevel" value="贵宾" @((Model.ELevel + "").Contains("贵宾") ? "checked" : "") datatype="*" nullmsg="请选择招待级别" />贵宾&nbsp;
                            <input type="checkbox" class="form-checkbox" name="ELevel" value="标准" @((Model.ELevel + "").Contains("标准") ? "checked" : "") datatype="*" nullmsg="请选择招待级别" />标准&nbsp;
                            <input type="checkbox" class="form-checkbox" name="ELevel" value="普通" @((Model.ELevel + "").Contains("普通") ? "checked" : "") datatype="*" nullmsg="请选择招待级别" />普通&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">申请事由</th>
                        <td colspan="2">
                            <textarea style="width:100%;" cols="3" name="ADesc" class='form-control' autocomplete="off" datatype="*" nullmsg="请填写申请事由">@Model.ADesc</textarea>
                        </td>
                        <th class="text-center">所需费用</th>
                        <td colspan="2">
                            <div class="input-group">
                                <input name="TotalMoney" class="form-control" value="@Model.TotalMoney"
                                       onkeypress="$.admin.keyPress(this)"
                                       onkeyup="$.admin.keyUp(this)"
                                       onblur="$.admin.keyBlur(this)" />
                                <span class="input-group-addon fix-border fix-padding"></span>
                                <select name="EntertainUnitName" class="form-control" style="width:80px;">
                                    @{
                                        foreach (var itemEntertainUnit in listEntertainUnit)
                                        {
                                            if (Model.EntertainUnitName.IsNotNullOrEmpty() && Model.EntertainUnitName.Equals(itemEntertainUnit.Name))
                                            {
                                                <option selected value="@itemEntertainUnit.Name">@itemEntertainUnit.Name</option>
                                            }
                                            else
                                            {
                                                <option value="@itemEntertainUnit.Name">@itemEntertainUnit.Name</option>
                                            }

                                        }
                                    }
                                </select>
                            </div>
                        </td>
                    </tr>
                    @if (listLog.Count > 0)
                    {
                        <tr>
                            <th class="text-center w-120px">审批日志</th>
                            <td colspan="5">
                                <table>
                                    @foreach (var item in listLog)
                                    {
                                        <tr>
                                            <td style="border:0;">@(item.LContent + "，" + item.CreateTime.ToDateFormat("yyyy-MM-dd HH:mm:ss"))</td>
                                        </tr>
                                    }
                                </table>
                            </td>
                        </tr>
                    }
                    <tr>
                        <th>请选择审批流程<span style="color:red">*</span></th>
                        <td colspan='9'>
                            <select class="form-control" style="max-width:80%;" name="FK_ApprovalId" datatype="*" nullmsg="请选择审批流程">
                                <option value="">==请选择==</option>
                                @foreach (var item in listApproval)
                                {
                                    <option value="@item.Id" @(Model.FK_ApprovalId == item.Id ? "selected" : "")>@item.DName</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td colspan='5'>
                            <a href='javascript:;' class='btn btn-primary' onclick='saveCaogao()'>存为草稿</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-primary' onclick='saveData()'>提交</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-back' onclick='goBack()'>返回</a>
                            <span id="spmsg"></span>
                        </td>
                    </tr>
                </table>
                <input type="hidden" id="submitMsg" value="" />
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#formMyEntertain").Validform({
            tiptype: function (msg, o, cssctl) {
                var objtip = $("#spmsg");
                cssctl(objtip, o.type);
                objtip.text(msg);
            },
            callback: function (form) {
                if ($("input[name='Status']").val() == "@ApplyStatus.草稿.ToInt()") {
                    win.showLoading("正在保存...");
                    $("#formMyEntertain").ajaxSubmit(function (data) {
                        if (data.Code == 300) {
                            win.alert(data.Message);
                        } else if (data.Code == 200) {
                            win.success($("#submitMsg").val(), function () {
                                goBack();
                            }, 1000);
                        }
                    });
                } else {
                    win.confirm("确认提交审批？", function () {
                        win.showLoading("正在保存...");
                        $("#formMyEntertain").ajaxSubmit(function (data) {
                            if (data.Code == 300) {
                                win.alert(data.Message);
                            } else if (data.Code == 200) {
                                win.success($("#submitMsg").val(), function () {
                                    goBack();
                                }, 1000);
                            }
                        });
                    });
                }
                return false;
            }
        });
        //$(".form-checkbox").click(function () {
        //    $(this).prop("checked", true).siblings().prop("checked", false);
        //});
    });
    function saveCaogao() {
        $("input[name='Status']").val("@(ApplyStatus.草稿.ToInt())");
        $("#submitMsg").val("保存草稿成功");
        $("#formMyEntertain").submit();
    }
    function saveData() {
        if(@Model.Id==0)$("input[name='Status']").val("@(ApplyStatus.新申请.ToInt())");
        $("#submitMsg").val("提交审批成功");
        $("#formMyEntertain").submit();
    }
    function goBack() {
        window.history.go(-1);
    }

</script>
